/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package actioncombination.logic.agent.knowledge;

import actioncombination.common.util.HibernateUtil;
import actioncombination.common.value.Value;
import actioncombination.logic.agent.action.Action;
import actioncombination.logic.agent.AgentState;
import java.io.Serializable;
import java.util.Collection;
import org.hibernate.HibernateException;
import org.hibernate.Session;



/**
 *
 * @author gisia
 */
public class Knowledge<T extends AgentState> {
    protected Collection<T> knowledge;
    public void save(T state){
        try {
            HibernateUtil.getInstance().getCurrentSession().beginTransaction();
            HibernateUtil.getInstance().getCurrentSession().save(state);
            HibernateUtil.getInstance().getCurrentSession().getTransaction().commit();
        } catch (HibernateException hibernateException) {
            HibernateUtil.getInstance().getCurrentSession().getTransaction().rollback();
            throw hibernateException;
        }
    };
    public  void update(T state){
         try {
            HibernateUtil.getInstance().getCurrentSession().beginTransaction();
            HibernateUtil.getInstance().getCurrentSession().update(state);
            HibernateUtil.getInstance().getCurrentSession().getTransaction().commit();
        } catch (HibernateException hibernateException) {
            HibernateUtil.getInstance().getCurrentSession().getTransaction().rollback();
            throw hibernateException;
        }
    };
    public  T get(int id){
        T state = null; 
        try {
            HibernateUtil.getInstance().getCurrentSession().beginTransaction();
           // state=(T) HibernateUtil.getInstance().getCurrentSession().load(T.class, id);
            HibernateUtil.getInstance().getCurrentSession().getTransaction().commit();
        } catch (HibernateException hibernateException) {
            HibernateUtil.getInstance().getCurrentSession().getTransaction().rollback();
            throw hibernateException;
        }
         return state;
    };
    
    public void addState(T state){
        knowledge.add(state);
    }

    public Collection<T> getKnowledge() {
        return knowledge;
    }

    public void setKnowledge(Collection<T> knowledge) {
        this.knowledge = knowledge;
    }

    
}
